<template>
  <div ref="chartRef" :style="{height, width}"/>
</template>
<script lang="ts">
import { defineComponent, ref, Ref, onMounted } from 'vue'
import { useECharts } from '@/hooks/useECharts'
import { basicProps } from './props'

export default defineComponent({
  name: 'ChartRadar',
  props: basicProps,
  setup() {
    const chartRef = ref<HTMLDivElement | null>(null)
    const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>)
    onMounted(() => {
      setOptions({
        title: {
          text: ''
        },
        legend: {
          data: ['预算分配', '实际开销']
        },
        radar: {
          axisName: {
            color: '#fff',
            backgroundColor: 'purple',
            borderRadius: 3,
            padding: [5, 5]
          },
          center: ['50%', '50%'],
          indicator: [
            { text: '销售', max: 6500 },
            { text: '管理', max: 16000 },
            { text: '信息技术', max: 30000 },
            { text: '客服', max: 38000 },
            { text: '研发', max: 52000 },
            { text: '市场', max: 25000 }
          ]
        },
        series: [
          {
            name: '预算 vs 开销（Budget vs spending）',
            type: 'radar',
            // areaStyle: {normal: {}},
            data: [
              {
                value: [4300, 10000, 28000, 35000, 50000, 19000],
                name: '预算分配（Allocated Budget）'
              },
              {
                value: [5000, 14000, 28000, 31000, 42000, 21000],
                name: '实际开销（Actual Spending）'
              }
            ]
          }
        ]
      })
    })
    return { chartRef }
  }
})
</script>
